package com.example.imagethumbnail.service;

import net.coobird.thumbnailator.Thumbnails;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;
import java.io.IOException;

@Service
public class ThumbnailService {
    public static final int WIDTH = 100;
    public static final int HEIGHT = 100;

    public String thumbnail(MultipartFile file, String uploadPath, String realUploadPath){

        try {
            String des = realUploadPath + File.separator +"thum_"+file.getOriginalFilename();
            Thumbnails.of(file.getInputStream()).size(WIDTH,HEIGHT).toFile(des);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {

        }
        return  uploadPath + File.separator +"thum_"+file.getOriginalFilename();


    }

}
